package uk.ac.lkl.common.util.ds.event;



import java.util.EventObject;

import uk.ac.lkl.common.util.ds.AbstractNotifyingList;


public class ListEvent<T> extends EventObject {

    private static final long serialVersionUID = 1L;


    private T element;


    private Integer oldIndex;


    private Integer newIndex;


    private ListEvent(AbstractNotifyingList<T> list, T element,
            Integer oldIndex, Integer newIndex) {
        super(list);
        this.element = element;
        this.oldIndex = oldIndex;
        this.newIndex = newIndex;
    }


    public static <T> ListEvent<T> createElementAddedEvent(AbstractNotifyingList<T> collection,
                                                           T element,
                                                           int index) {
        return new ListEvent<T>(collection, element, null, index);
    }


    public static <T> ListEvent<T> createElementRemovedEvent(AbstractNotifyingList<T> collection,
                                                             T element,
                                                             int index) {
        return new ListEvent<T>(collection, element, index, null);
    }


    public static <T> ListEvent<T> createElementMovedEvent(AbstractNotifyingList<T> collection,
                                                           T element,
                                                           int oldIndex,
                                                           int newIndex) {
        return new ListEvent<T>(collection, element, oldIndex, newIndex);
    }


    public AbstractNotifyingList<T> getList() {
        return (AbstractNotifyingList<T>) getSource();
    }


    public T getElement() {
        return element;
    }


    public Integer getOldIndex() {
        return oldIndex;
    }


    public Integer getNewIndex() {
        return newIndex;
    }

}
